import 'package:flutter/material.dart';
import 'package:get/get.dart';

class HLAppBar extends AppBar {
  /// 标题
  final String? navigationTitle;

  /// 标题Widget
  final Widget? navigationTitleWidget;

  /// 是否显示返回按钮
  final bool showBackLeading;

  /// 返回事件
  final Function()? backAction;

  /// 左侧按钮
  final Widget? leftWidget;

  /// 是否显示底部分割线
  final bool showBottomLine;

  HLAppBar({
    super.key,
    this.navigationTitle,
    this.navigationTitleWidget,
    this.showBackLeading = true,
    this.showBottomLine = false,
    this.backAction,
    this.leftWidget,
    super.automaticallyImplyLeading,
    super.actions,
    super.flexibleSpace,
    super.bottom,
    super.scrolledUnderElevation,
    super.notificationPredicate,
    super.surfaceTintColor,
    super.shape,
    super.backgroundColor = Colors.white,
    super.foregroundColor,
    super.iconTheme,
    super.actionsIconTheme,
    super.primary = true,
    super.centerTitle,
    super.excludeHeaderSemantics = false,
    super.titleSpacing,
    super.toolbarOpacity = 1.0,
    super.bottomOpacity = 1.0,
    super.toolbarHeight,
    super.leadingWidth,
    super.toolbarTextStyle,
    super.titleTextStyle,
    super.systemOverlayStyle,
    super.forceMaterialTransparency = false,
    super.clipBehavior,
  });

  @override
  Widget? get title {
    if (navigationTitleWidget != null) {
      return navigationTitleWidget;
    }
    if (navigationTitle == null) {
      return Container();
    }
    return Text(
      navigationTitle!,
      style: TextStyle(
        fontSize: 18,
        color: Colors.black,
        fontWeight: FontWeight.bold,
      ),
    );
  }

  @override
  Widget? get leading {
    return Row(
      children: [
        /// 返回按钮
        showBackLeading
            ? GestureDetector(
                child: Icon(Icons.arrow_back_ios_sharp, color: Colors.black),
                onTap: () {
                  if (backAction != null) {
                    backAction!();
                    return;
                  }
                  Get.back();
                },
              )
            : Container(),

        /// 左侧其他图标
        leftWidget ?? Container()
      ],
    ).paddingOnly(left: 16);
  }

  @override
  // TODO: implement elevation
  double? get elevation => showBottomLine ? 0.5 : 0;

  @override
  // TODO: implement shadowColor
  Color? get shadowColor => Color.fromRGBO(238, 238, 238, 1);
}
